a = int(input())
if 1000 > a or 9999 < a:
    print(0)
    exit()
n = []
sim_num = []
for i in range(4):
    n.append(int(str(a)[i]))

def sim_num_check():
    delit = 2
    for i in range(2, ns):
        if ns % i == 0:
            delit += 1
        if delit > 2:
            break
    if delit == 2:
        max_sim_num.append(ns)


for i in range(4):
    sim_num.append(n[i])
nms = 0
for i in range(3):
    nms = int(str(n[i]) + str(n[i + 1]))
    sim_num.append(nms)
    nms = 0
for i in range(2):
    nms = int(str(n[i]) + str(n[i + 1]) + str(n[i + 2]))
    sim_num.append(nms)
sim_num.append(a)

max_sim_num = []
max_sim_num.append(0)
for i in range(10):
    ns = sim_num[i]
    sim_num_check()
print(max(max_sim_num))